/* 签名管理
 * @Author: wujie 
 * @Date: 2018-06-12 11:06:22 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-07-02 18:49:12
 */
import React,{ Component } from 'react'
import { Row, Modal } from 'antd'
import components from '@/components'
import { connect } from 'react-redux';
import enumActions from '@/actions/enum'
import actions from '@/actions/sign'
import signEditActions from '@/actions/signEdit'
import util from '@/utils'

const { Card, SignSearch, SignTable} = components

const confirm = Modal.confirm

class Sign extends Component {

  render(){

    const searchProps = util.pick(this.props, [
      'sign',
      'status',
      'startTime',
      'endTime',
      'signStatusEnum',
    ])

    const searchFunProps = util.pick(this, [
      'onChangeSign',
      'onChangeStatus',
      'onChangeStartTime',
      'onChangeEndTime',
      'onSearch',
      'onAdd'
    ])

    const tableProps = util.pick(this.props, [
      'data',
      'signStatusEnum',
      'industryEnum',
      'scenariosEnum',
      'pageNum',
      'pageSize',
      'total',
      'loading',
    ])

    const tableFunProps = util.pick(this, [
      'onSetDefault',
      'onDelete',
      'onFilterStatus',
      'onChangePagination',
    ])

    return (
      <div>
        <Card title="签名管理">
          <Row style={{padding: 24, backgroundColor: '#fff'}}>
            <SignSearch {...searchProps} {...searchFunProps} />
            <SignTable {...tableProps} {...tableFunProps} />
          </Row>
        </Card>
      </div>
    )
  }

  componentDidMount() {
    this.props.getData()
    this.props.getSignStatusEnum()
    this.props.getIndustryEnum()
    this.props.getScenariosEnum()
  }

  onAdd = () => {
    this.props.history.push('/index/signEdit')
  }

  onChangeSign = ({ target: { value }}) => {
    this.props.setSign(value)
  }

  onChangeStatus = (val) => {
    this.props.setStatus(val)
  }

  onChangeStartTime = (val) => {
    this.props.setStartTime(val)
  }

  onChangeEndTime = (val) => {
    this.props.setEndTime(val)
  }

  onSearch = () => {
    this.props.setPageNum(1)
    this.props.getData()
  }

  // 编辑不要了
  // onEdit = (value, index) => {
  //   this.props.passDataToEdit(value)
  //   this.props.history.push('/index/signEdit')
  // }

  onDelete = (value, index) => {
    const _this = this
    confirm({
      title: '提示',
      maskClosable: true,
      content: '确定删除此条记录？',
      onOk(){
        _this.props.deleteSign(value)
      }
    })
  }

  onSetDefault = (value, index) => {
    this.props.setDefault(value)
  }

  onChangePagination = (value) => {
    this.props.setPageNum(value)
    this.props.getData()
  }

} 

const mapStateToProps = ({ signReducer, enumReducer }) => ({ ...signReducer, ...enumReducer })

const mapDispatchToProps = { ...actions, passDataToEdit: signEditActions.setData, ...enumActions }

export default connect(mapStateToProps, mapDispatchToProps)(Sign)